package com.sky.order.controller;

import com.sky.order.domain.common.Response;
import com.sky.order.domain.Order;
import com.sky.order.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequestMapping("/api/v1/order")
@CrossOrigin("*")
@RestController
public class OrderController {

    @Autowired
    private IOrderService orderService;

    @RequestMapping(value = "/query_order/{id}", method = RequestMethod.GET)
    public Response<Order> queryOrderById(@PathVariable("id") String orderId) {
        try {
            Order order = orderService.queryOrderById(orderId);
            return Response.<Order>builder()
                    .code(Response.ResStatus.SUCCESS.getCode())
                    .message(Response.ResStatus.SUCCESS.getInfo())
                    .data(order)
                    .build();
        } catch (Exception e) {
            log.error("error:{}", e.getMessage(), e);
            return Response.<Order>builder()
                    .code(Response.ResStatus.ERROR.getCode())
                    .message(Response.ResStatus.ERROR.getInfo())
                    .build();
        }
    }


}
